package qingke.struts.example1.action;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.List;

import com.opensymphony.xwork2.ActionSupport;

import qingke.struts.example1.dao.WebDao;
import qingke.struts.example1.model.Message;
import qingke.struts.example1.model.People;

public class StreamAction1  extends ActionSupport{
	
	private InputStream inputStream;
	private WebDao webDao=new WebDao();
	private String fileName;
	
	public StreamAction1(){
		
	}
	
	public String execute(){
		
		List<People> peoples=webDao.getAllPeople();
		String content="id,name,age,height\n";
		for(People people:peoples){
			content+= people.getId()+","+people.getName()+","+people.getAge()+","+people.getHeight()+"\n";
		}
		inputStream=new ByteArrayInputStream(content.getBytes());
		fileName="download.csv";
		return SUCCESS;
		
		
	}

	public InputStream getInputStream() {
		return inputStream;
	}

	public void setInputStream(InputStream inputStream) {
		this.inputStream = inputStream;
	}

	public String getFileName() {
		return fileName;
	}

	public void setFileName(String fileName) {
		this.fileName = fileName;
	}
	
	
	
	

}
